<?php
header("Content-Type: text/html;charset=utf-8");
include('system/db/conn.php');
session_start();
$allid = $_GET['allid'];
$allnum = $_GET['allnum'];
$allmoney = $_GET['allmoney'];
$songtype=$_GET['songtype'];
$songcantime=$_GET['songcantime'];
$ordermessage=$_GET['ordermessage'];
$orderphone="";
$uuserid=0;
$userAddress=""; 
$username="";
if($songtype==1){
    $consigneeid=$_GET['consigneeid'];
    $check_query2  = mysql_query("select * from do_user_consignee where id=".$consigneeid);
    if($result = mysql_fetch_array($check_query2)){
    $check_query3 = mysql_query("select * from do_user where id=".$result['user_id']);
    if($result3 = mysql_fetch_array($check_query3)){
        $username=$result3['user_name'];
    } 

        $userAddress = $result['address'];
        $orderphone =$result['mobile'];
        $uuserid=$result['user_id'];
    }
}elseif ($songtype==0) {
    if(isset($_SESSION['userid'])){
        $uuserid=$_SESSION['userid'];
        $username=$_SESSION['username'];
$sql5 = "INSERT INTO do_user_consignee(user_id,address,mobile,consignee,is_defult,songcantime)VALUES
($uuserid,'".$_GET['newAddress']."','".$_GET['newphonenum']."','$username',1,'$songcantime')";
if(mysql_query($sql5,$conn)){
 
}else{
    echo "插入新的地址错误";
}





    }
    $orderphone=$_GET['newphonenum'];
    $userAddress=$_GET['newAddress'];
}

$arrayId = split(",", $allid);
$arrayNum = split(",", $allnum);
$orderNum = date('YmdHis').rand(0,9999);    
$orderDate   = time();

$supplierid=$_GET['supplierid'];

$candian="";
  $count_array = count($arrayId);
for($i=0;$i<$count_array;$i++){
    if($i==0){
    $candian=$candian.$arrayId[$i].",".$arrayNum[$i];
    }else{
         $candian=$candian." ".$arrayId[$i].",".$arrayNum[$i];
    }
}



$sql = "INSERT INTO do_deal_order(order_sn,user_id,create_time,total_price,pay_amount,address,user_name,mobile,supplier_id,food,order_status,ordermessage,type,is_delete,songcantime)VALUES
('$orderNum',".$uuserid.",'$orderDate',$allmoney,$allmoney,'$userAddress','".$username."','$orderphone',$supplierid,'$candian',1,'$ordermessage',0,0,'$songcantime')";
echo $sql;
if(mysql_query($sql,$conn)){
 echo "success";
}else{
    echo "error";
} 




?>